// pages/personal/myOrder/refundDetail/refundDetail.js
import { queryDetail, cancelRefund } from '../../../../../config/config'
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    refundStatusList: [],
    steps: [
      {
        index: 0,
        text: '提交申请',
        activeIcon: true,
        icon: 'icondaifukuan'
      },
      {
        index: 1,
        text: '商家审核',
        activeIcon: true,
        icon: 'iconhuodong'
      },
      {
        index: 2,
        text: '退款中',
        activeIcon: false,
        icon: 'iconbianji'
      },
      {
        index: 3,
        text: '退款完成',
        activeIcon: false,
        icon: 'icondianpu'
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options) {
      this.refundDetail(options.id)
    }
    // 退款状态值列表
     let refundStatusList = app.globalData.getListvalue(app.globalData.valLsit, 'REFUND_STATUS')
     this.setData({
      refundStatusList: refundStatusList
     })
  },
 // 获取退款详情
 refundDetail(id) {
   let queryDetailUrl = queryDetail + '/' + id
  app.reqFun.requestJson('GET',queryDetailUrl,'',(res)=>{
    if(res.data.success === 1) {
      let refundStatusList = this.data.refundStatusList
      let steps = this.data.steps
      if (res.data.data.refundStatus == '3' || res.data.data.refundStatus == '4') {
        steps[2].activeIcon = true
        this.setData({
          steps: steps
        })
      }
      if (res.data.data.refundStatus == '5' || res.data.data.refundStatus == '6') {
        steps[2].activeIcon = true
        steps[3].activeIcon = true
        this.setData({
          steps: steps
        })
      }
      res.data.data.skuSpecs = JSON.parse(res.data.data.skuSpecs)
      let refundTypelist = app.globalData.getListvalue(app.globalData.valLsit, 'REFUND_TYPE')
      let refundReasonlist = app.globalData.getListvalue(app.globalData.valLsit, 'REFUND_REASON')
      let refundName = this.filterByName(refundTypelist, res.data.data.refundType)
      let refundReasonName = this.filterByName(refundReasonlist, res.data.data.refundReason)
      this.setData({
        refundData: res.data.data,
        refundName: refundName,
        refundReasonName: refundReasonName,
        refundStatusList: this.filterByName(refundStatusList, res.data.data.refundStatus)
      })
    }
  })
},
cancellationRefund() {
  let cancelRefundUrl = cancelRefund+'/' +　this.data.refundData.id
  app.reqFun.requestJson('POST',cancelRefundUrl,'',(res)=>{
    if(res.data.success==1){
      wx.showToast({
        title: '取消成功',
        icon: 'success',
        duration: 2000
      })
      wx.navigateBack({
        delta: 1,
      })
    } else {
      wx.showToast({
        title: '取消退款失败',
        icon: 'none',
        duration: 2000
      })
    }
  })
},
goreBack(e){
  wx.navigateBack({
    delta: 1,
  })
},
filterByName(aim, name) {
  return aim.filter(item => item.val == name)
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})